<?php

namespace addons\sum\controller;


use addons\sum\controller\Base;
use addons\sum\model\User as UserModel;
use app\admin\model\sum\FaqComment as FaqCommentModel;

class Faq extends Base
{

    protected $noNeedLogin = ['index','detail','doLike'];
    protected $noNeedRight = ['*'];


    // faq 列表
    public function index()
    {
        $search=$this->request->get('search');
        $map=[];
        if($search){
            $map['title'] = ['like', '%'.$search.'%'];
        }
        $this->success('获取成功', \addons\sum\model\Faq::where($map)->order('id', 'DESC')->paginate(10));
    }


    public function detail () {
        $id = $this->request->get('id');
        $this->success('获取成功', \addons\sum\model\Faq::where('id', $id)->find());
    }

    /**
     * 已解决点赞
     * @return void
     */
    public function doLike () {
        $id = $this->request->request('id');
        $this->success('操作成功', \addons\sum\model\Faq::where('id', $id)->setInc('views'));
    }

    /**
     * 未解决评价
     * @return void
     */
    public function comment ()
    {
        $params = $this->request->post();
        $user = UserModel::info();
        FaqCommentModel::create([
            'faq_id' => $params['faq_id'],
            'user_id' => $user->id,
            'content' => $params['content']
        ]);
        // 表单验证
        $this->success('评价成功');
    }
}
